#ifndef API_CONTROLLER_H
#define API_CONTROLLER_H

#include <memory>

#include <crow.h>

#include "has_changes_handler.h"
#include "session/changes_manager.h"
#include "session/permission_manager.h"

#include "data_controller.h"

namespace Api
{

class GetIdsHandler;
class GetElementsHandler;
class AddElementHandler;
class SetElementHandler;
class DelElementHandler;
class HasChangesHandler;
class LoginHandler;
class LogoutHandler;

class ApiController final
{
public:
    ApiController();
    ~ApiController();

    void run();

    std::shared_ptr<DataController> dataController() const;
    void setDataController(std::shared_ptr<DataController> m_dataController);

    std::shared_ptr<PermissionManager> permissionManager() const;
    void setPermissionManager(std::shared_ptr<PermissionManager> m_permissionManager);

    ChangesManager& changesManager();

private:
    std::unique_ptr<crow::SimpleApp> m_crowApplication;
    std::unique_ptr<GetIdsHandler> m_getIdsHandler;
    std::unique_ptr<GetElementsHandler> m_getElementsHandler;
    std::unique_ptr<AddElementHandler> m_addElementHandler;
    std::unique_ptr<SetElementHandler> m_setElementHandler;
    std::unique_ptr<DelElementHandler> m_delElementHandler;
    std::unique_ptr<HasChangesHandler> m_hasChangesHandler;
    std::unique_ptr<LoginHandler> m_loginHandler;
    std::unique_ptr<LogoutHandler> m_logoutHandler;

    std::shared_ptr<DataController> m_dataController;
    std::shared_ptr<PermissionManager> m_permissionManager;

    ChangesManager m_changesManager;
};

} // namespace Api

#endif // API_CONTROLLER_H
